<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>新增角色</title>

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="css/animate.min.css" rel="stylesheet">
    <link href="css/style.min862f.css?v=4.1.0" rel="stylesheet">



</head>

<body class="gray-bg" style="height: 260px;">


<div class="col-sm-6"  style="padding-left: 0px;padding-right: 0px;">
    <div class="ibox float-e-margins" style="margin-bottom: 0px;">

        <div class="ibox-content">
            <form class="form-horizontal m-t" id="editForm">
                <input id="jsdm" name="jsdm" value="" type="hidden">
                <input id="jgbm" name="jgbm" value="" type="hidden">
                <input id="cjsj" name="cjsj" value="" type="hidden">

                <div class="form-group">
                    <label class="col-sm-4 control-label">角色名称：</label>

                    <div class="col-sm-3">
                        <input id="jsmc" maxlength="32" name="jsmc" minlength="2" type="text" class="form-control input-mb" required=""
                               aria-required="true">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-4 control-label">角色描述：</label>

                    <div class="col-sm-3">
                        <input id="jsms" maxlength="64" name="jsms" minlength="2" type="text" class="form-control" required=""
                               aria-required="true">
                    </div>
                </div>

               <!-- <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-3">
                        <button class="btn btn-primary" type="button" onclick="update();">保存</button>
                    </div>
                </div>-->
                <footer class="text-center">
                    <div class="hr-line-dashed"></div>
                    <button class="btn btn-primary" type="button" onclick="update()"><strong>保存</strong></button>
                </footer>
            </form>
        </div>
    </div>

</div>

<script type="text/javascript" src="js/jquery.min.js?v=3.5.1"></script>
<script type="text/javascript" src="js/bootstrap.min.js?v=3.3.6"></script>
<script type="text/javascript" src="js/plugins/layer/layer.min.js"></script>
<script type="text/javascript" src="platcommon/layer-wn.js?v=1.0.0"></script>
<script type="text/javascript" src="platcommon/json-form.js?v=1.0.0"></script>
<script type="text/javascript" src="platcommon/common.js?v=1.0.0"></script>
<script>

    $(document).ready(function () {
        getRoleInfo(Common.GetRequest().jsdm);
    });


    //绑定事件
    function update() {
        if (validate()) {
            var jgbm = $.trim($("#jgbm").val());
            var jsdm = $.trim($("#jsdm").val());
            var jsmc = $.trim($("#jsmc").val());
            var jsms = $.trim($("#jsms").val());
            var cjsj = $.trim($("#cjsj").val());
            $.ajax({
                type: "POST",
                contentType: 'application/json',
                dataType: "json",
                url: "role/update",
                data: JSON.stringify({
                    'jsmc': jsmc,
                    'jsms': jsms,
                    'jsdm': jsdm,
                    'jgbm': jgbm,
                    'jsdm': jsdm,
                    'cjsj': cjsj,
                }),
                success: function (jsonData) {
                    if (jsonData.code == 200) {   //查询成功
                        LayerWn.showSucAlert('更新成功!');

                        for(var k=0;k<parent.frames.length;k++){
                            if(parent.frames[k].frameElement.src.indexOf("plat-role.html")!=-1)
                                parent.frames[k].queryRoleList();
                        }
                        setTimeout("parent.$('#select').click()",1000);
                        setTimeout("parent.layer.closeAll()",2000);
                    } else {
                        LayerWn.showFailAlert('更新失败!'+ jsonData.msg);
                        parent.layer.closeAll();
                    }
                }
            });
        }
    }
    //数据校验
    function validate() {
        var jsmc = $.trim($("#jsmc").val());
        if (jsmc == '') {
            LayerWn.showAlert('角色名称不能为空');
            return false;
        }
        return true;
    }


    //角色详情
    function getRoleInfo(jsdm) {
        $.ajax({
            type: "GET",
            contentType: 'application/json',
            dataType: "json",
            url: "role/getroleinfo/" + jsdm,
            success: function (jsonData) {
                if (jsonData.code == 200) {   //查询成功
                    $('#editForm').populateForm(jsonData.sce);
                } else {

                }
            }
        });
    }


    //时间格式转换
    function data_string(str, value) {
        if (value == "yyyy-MM-dd hh:mm:ss") {
            var d = eval('new ' + str.substr(1, str.length - 2));
            var ar_date = [d.getFullYear(), d.getMonth() + 1, d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds()];
            for (var i = 0; i < ar_date.length; i++) ar_date[i] = dFormat(ar_date[i]);
            return ar_date.slice(0, 3).join('-') + ' ' + ar_date.slice(3).join(':');
            function dFormat(i) {
                return i < 10 ? "0" + i.toString() : i;
            }
        }
        else if (value == "yyyy-MM-dd") {
            var d = eval('new ' + str.substr(1, str.length - 2));
            var ar_date = [d.getFullYear(), d.getMonth() + 1, d.getDate()];
            for (var i = 0; i < ar_date.length; i++) ar_date[i] = dFormat(ar_date[i]);
            return ar_date.join('-');
            function dFormat(i) {
                return i < 10 ? "0" + i.toString() : i;
            }
        }
    }

</script>
</body>

</html>
